package com.dragon.test.springbootdemo.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: longtao
 * @Date: 2019/5/13
 * @Version: 1.0
 * @Description: page dispatcher
 */
@Controller
public class PageController {

    @RequestMapping(value = "/hello")
    @ResponseBody
    //@ResponseStatus(value = HttpStatus.OK) // 设置http返回状态码，方法1
    public ResponseEntity hello(String hello, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){




        // 设置http返回状态码，方法2
        //httpServletResponse.setStatus(HttpStatus.OK.value());

        System.out.println(hello);

        String result = "We already receive your message:" + hello;
        Map res = new HashMap(1);
        res.put("result",result);

        // 设置http返回状态码，方法3。
        //return new ResponseEntity(res, HttpStatus.INTERNAL_SERVER_ERROR);
        return new ResponseEntity(res, HttpStatus.OK);
    }




}
